<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .active{
            color: skyblue;
        }
    </style>
    <script type="text/javascript" src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
        <ul>
            <!-- 
            1.v-for 遍历数组生成多个Li列表
            2.同时获取数据和索引
            3.@click绑定函数传入当前li的索引
            4.在函数中将当前索引值给currentIndex变量
            5.：class 添加样式
            -->
            <li v-for="(item,index) in title" @click="liClick(index)" :class="{active:currentIndex==index}">{{item}}</li>
        </ul>
    </div>
    <script>
        const app=new Vue({
            el:'#app',
            data:{
                title:['1','2','3','4'],
                currentIndex:0
            },
            methods: {
                liClick(index){
                    this.currentIndex=index
                }
            },
        })
    </script>
</body>
</html>